package com.skhu.as.dao;

import org.springframework.jdbc.core.JdbcTemplate;

import com.skhu.as.domain.PresentCondition;

public class PresentConditionD {

	private JdbcTemplate jdbcTemplate;

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public int getPresentConditionMaxNo(){
		String sql = "SELECT MAX(present_condition_no) FROM present_condition";
		int maxNo = jdbcTemplate.queryForInt(sql);
		return maxNo;
	}
	
	public int insertPresentCondition(PresentCondition presentCondition){
		String sql = "INSERT INTO present_condition VALUES (?,?,?,?,?)";

		Object[] param = new Object[]{
				presentCondition.getPresentConditionNo(),
				presentCondition.getFaultHandlingNo(),
				presentCondition.getWorkerNo(),
				presentCondition.getDate(),
				presentCondition.getContent()
		};
		
		int result = jdbcTemplate.update(sql, param);
		return result;
	};
	
	public int deletePresentCondition(int presentConditionNo){
		String sql = "DELETE FROM present_condition WHERE present_condition_no = ?";

		Object[] param = new Object[]{
				presentConditionNo
		};
		
		int result = jdbcTemplate.update(sql, param);
		return result;
	}
	
}
